﻿using System.IO;
using System.Web;

namespace Medianamik.Core.Sugar
{
    public static class FileUtil
    {
        public static void FileToHttpResponse(this MemoryStream file, string fileName, string contentType)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.ContentType = contentType;
            HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment;filename={0}", fileName));
            HttpContext.Current.Response.Charset = "";
            HttpContext.Current.Response.BinaryWrite(file.ToArray());
            HttpContext.Current.Response.End();
        }
    }
}